#include <iostream>
using namespace std;

int main() {
	 ios::sync_with_stdio(false);
     cin.tie(0);cout.tie(0);

    int N;
    while (cin >> N && N != 0) {
        int* arr = new int[N];
        for (int i = 0; i < N; ++i) {
            cin >> arr[i];
        }//输入到数组

        int mode = arr[0];
        int maxCount = 1;
        int currentVal = arr[0];
        int currentCount = 1;

        for (int i = 1; i < N; ++i) {
            if (arr[i] == currentVal) {
                currentCount++;
            } else {
                if (currentCount > maxCount ) {
                    maxCount = currentCount;
                    mode = currentVal;
                }
                currentVal = arr[i];
                currentCount = 1;
            }
        }

        // 处理最后一个连续段
        if (currentCount > maxCount ) {
            mode = currentVal;
        }

        cout << mode << endl;
    }

    return 0;
}